package com.itheima.demo03JDBC增_删_改数据重点;

import java.sql.*;

/*
    建议Java里面写SQL语句,可以先在SQLYog中写好.复制到代码
 */
public class Demo03 {
    public static void main(String[] args) throws SQLException {
        // 1.注册驱动(自动注册)
        // 2.获取Connection连接
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql_day2", "root", "root");
        // 3.获取Statement(小货车)
        Statement statement = connection.createStatement();
        // 4.执行SQL语句
//        String sql = "select * from st2";
//        ResultSet resultSet = statement.executeQuery(sql);
//        // 5.处理结果
//        while (resultSet.next()){
//            int id = resultSet.getInt("id");
//            String name = resultSet.getString("NAME");
//            int age = resultSet.getInt("age");
//            System.out.println(id+"="+name+"="+age);
//        }
//        String sql = "INSERT INTO st2 VALUES (null, 'zhangsan', 24);";
//        String sql = "update st2 set age = 12 where name = 'zhangsan'";
        String sql = "delete from st2 where name = 'zhangsan'";


        int row = statement.executeUpdate(sql);
        System.out.println("影响行数："+row);
        // 6.释放资源

        statement.close();
        connection.close();
    }
}
